<?php
require_once 'common.inc.php';
require_once './deploy/alarm_config.php';
if ($action == 'show') {
	if ($type == 'acs') {
		if ($item == 'alarm') {
			include_once MCC_ROOT . '/templates/msystem/deploy.html';
		} else {
			include_once MCC_ROOT . '/templates/msystem/deploy.html';
		} 
	} 
	if ($type == 'rds') {
		if ($item == 'alarm') {
			include_once MCC_ROOT . '/templates/msystem/deploy.html';
		} else {
			include_once MCC_ROOT . '/templates/msystem/deploy.html';
		} 
	} 
	if ($type == 'ics') {
		$status = array('0' => array('0' => '分光', '1' => '镜像'),
			'1' => array('0' => '推送页', '1' => '透明'),
			'2' => array('0' => '万'),
			'3' => array('0' => '否', '1' => '是'),
			'4' => array('0' => '否', '1' => '是'),
			'5' => array('0' => '强制', '1' => '普通'),
			'6' => array('0' => '否', '1' => '是',)
			);

		include_once MCC_ROOT . '/templates/msystem/deploy.html';
	} 
	if ($type == 'wcs') {
		if ($item == 'alarm') {
			include_once MCC_ROOT . '/templates/msystem/deploy.html';
		} else {
			include_once MCC_ROOT . '/templates/msystem/deploy.html';
		} 
	} 
	if ($type == 'tracker') {
		if ($item == 'alarm') {
			include_once MCC_ROOT . '/templates/msystem/deploy.html';
		} elseif ($item == 'detail') {
			$trackercontent = '';
			if (file_exists('tracker.txt')) {
				$trackercontent = file_get_contents('tracker.txt');
			} 
			include_once MCC_ROOT . '/templates/msystem/deploy.html';
		} else{
			include_once MCC_ROOT . '/templates/msystem/deploy.html';
		}
	} 
} elseif ($action == 'edit') {
	$file = './deploy/alarm_config.php';
	if ($type == 'acs') {
		$acs[0] = $num1;
		$acs[1] = $num2;
		$acs[2] = $num3;
		$acs[3] = $num4;
		$acs[4] = $num5;
	} 
	if ($type == 'rds') {
		$rds[0] = $num1;
		$rds[1] = $num2;
		$rds[2] = $num3;
		$rds[3] = $num4;
	} 
	if ($type == 'ics') {
		$woso[1]=$num1;
		$woso[2]=$num2;
	} 
	if ($type == 'wcs') {
		$wcs[0] = $num1;
		$wcs[1] = $num2;
		$wcs[2] = $num3;
	} 
	if ($type == 'tracker') {
		if($item=='alarm'){
			$tra[0] = $num1;
			$tra[1] = 0;
		}
		if ($item == 'detail') {
			$trackertext = 'd8:announce';
			$arr = array();
			if (!$trackercontent) {
				adminmsg('没有填写tracker', 'deploy.php?action=show&type=' . $type);
				exit();
			} 
			$ftracker = fopen('tracker.txt', 'wb+');
			if ($ftracker) {
				fwrite($ftracker, $trackercontent);
				fclose($ftracker);
			} 

			$arr = explode(';', $trackercontent);
			$i = 0;
			$count = count($arr);
			for($i = 0;$i < $count;$i++) {
				if (strpos($arr[$i], '//')) {
					if ($i == 0) {
						$arr[$i] = $arr[$i] . '/announce';
						$length = strlen($arr[$i]);
						$trackertext .= $length . ':' . $arr[$i];
					} else {
						$arr[$i] = $arr[$i] . '/announce';
						$length = strlen($arr[$i]);
						if ($i == 1)
							$trackertext .= '13:announce-listll' . $length . ':' . $arr[$i];
						else
							$trackertext .= $length . ':' . $arr[$i];
						if ($i == $count-1) {
							$trackertext .= 'ee';
						} else
							$trackertext .= 'el';
					} 
				} 
			} 
			$fp = fopen('../push/trackerlist.php', 'wb+');
			if ($fp) {
				fwrite($fp, $trackertext);
				fclose($fp);
			} 
			adminmsg('添加成功', 'deploy.php?action=show&type=' . $type);
		} 
	} 
	$str = "<?php \n" . 
		"\$acs = array(" . implode(',', $acs) . ");//总流量；单链接流量；缓存种子；预缓存种子；空间\n" . "\$rds = array(" . implode(',', $rds) . ");//抓取种子；预缓存；GET值\n" . 
		"\$wcs = array(" . implode(',', $wcs) . ");//被动抓取值；预缓存；空间\n" . 
		"\$woso = array(" . implode(',', $woso) . ");//我搜访问次数;推送页显示次数；下载种子次数\n" . "\$tra = array(" . implode(',', $tra) . ");//重定向次数\n" . 
		"?>";
	write_file($file, $str, $type);
} 

function write_file($filename, $str, $type) {
	$fp = fopen($filename, 'wb+');
	if ($fp) {
		fwrite($fp, $str);
		fclose($fp);
		adminmsg('修改成功', 'deploy.php?action=show&type=' . $type);
	} else
		adminmsg('修改失败', 'deploy.php?action=show&type=' . $type);
} 

?>